﻿using System.Collections.Generic;
using OWL.Rendering.HRP;
using Yoozoo.Core.Extensions.CSharp;
using Yoozoo.Gameplay.City.Blueprint.Node;
using Yoozoo.Gameplay.Liberty;
using Yoozoo.Gta.Common;

namespace Yoozoo.Gameplay.City
{
    public static class InnerCityBluprintUtils
    {
        public static void SwitchInnerCityDailyStage(float timeSpeed, float startProgress, List<BlueprintDailyStageSetting> stageTimeSetting)
        {
            var dailyData = HRenderSettingsManager.Get().GetData<HcitySunoRainData>();
            if (dailyData != null)
            {
                if (timeSpeed < 0)
                {
                    timeSpeed = 0;
                }
                var setSunOrRainInstance = SetSunorRain.getInstance();
                
                
                if (stageTimeSetting.IsNotEmpty())
                {
                    setSunOrRainInstance.ResetStageProgress();
                    for (int i = 0; i < stageTimeSetting.Count; i++)
                    {
                        setSunOrRainInstance.UpdateStageTime(stageTimeSetting[i].Stage, stageTimeSetting[i].StageTime);
                    }
                    setSunOrRainInstance.CalculateStageProgress();
                }

                if (startProgress < 0)
                {
                    setSunOrRainInstance.CalculateCurrentStage();
                }
                else
                {
                    setSunOrRainInstance.UpdateProgress(startProgress);
                }

                setSunOrRainInstance.SetStageBySpeed();
                setSunOrRainInstance.RaintoSunupdate(); // 手动更新一下当前表现，避免TimeSpeed过大导致变化不及时。
                setSunOrRainInstance.TimeSpeed = timeSpeed;
            }
        }
        
        public static void UnlockCityRealAiNpc(int buildingId, string eventRecordId)
        {
            BlueprintUtils.SendRecordRequest(eventRecordId);
            ResidentHandler.Inst.GetFunction("CityLuaFunction.unlockCityRealAiNpc").Action(buildingId, eventRecordId);
        }

        public static void CallLuaDailyStageChanged(int stageId, float leftTime)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.onDailyStageChange").Action(stageId, leftTime);
        }
    }
}